


    import * as React from 'react';
    import * as ReactDOM from 'react-dom';


    var $input = require("./input.js");
    var INPUT = $input.INPUT;
    var INPUTMLEAVE = $input.INPUTMLEAVE;
    /*input label插件*/
    var INPUT_LABEL = $input.INPUT_LABEL;
    var INPUT_DISPLAY = $input.INPUT_DISPLAY;
    /*textarea插件*/
    var TEXTAREA = $input.TEXTAREA;
    /*验证插件*/
    var VALIDE = require("./valide.js").VALIDE;
    var SELECT = require("./select-table.js").SELECT;
    var LIST_SELECT = require("./list-select-table.js").LIST_SELECT;

    var UPIMGAE = require("./upiamge.js").UPIMGAE;


    var RADIO = require("./radio.js").RADIO;
    var CHECKBOX = require("./radio.js").CHECKBOX;
    var CALENDAR = require("./calendar");
    var SELECT_STATIC = require("./select-static.js").SELECT;
    var RADIO_STATIC = require("./radio-static.js").RADIO;


    var IN = React.createClass({
        getDefaultProps: function () {
            return {
                type: 'INPUT', title: "大哥你先设置个title", isStar: false, cssLength: 1, isShow: true, isRefresh: false,
                css: {
                    0: "",
                    1: "one",
                    2: "two",
                    3: "three",
                    4: "four"
                },
                placeholder: "",
                isShowColon: true,
                vaDoneMethod: false,
            };
        },
        componentWillMount: function () {

            /*if (this.props.param.isShow == false) {
             this.setFormValue("");
             } else {
             this.setFormValue(this.props.param.defaultValue ? this.props.param.defaultValue : "");
             }*/
        },
        handleBlur: function (value,isDoDone) {

            console.log("进入验证方法" + value);
            var param = this.props.param, vaMessage = "", temp = {};
            if (value == "" && param.isStar) {
                param.errorMessage = "不能为空!";
            } else if (param.vaMethod) {
                vaMessage = param.vaMethod(value, this);
                param.errorMessage = vaMessage;
            } else {
                param.errorMessage = true;
            }
            temp[this.props.param.name] = param;
            this.props.changState(temp);
            param.errorMessage&&isDoDone!=false&&this.props.param.vaDoneMethod && this.props.param.vaDoneMethod(value, this);
        },
        handleFocus: function () {
            var param = this.props.param, temp = {};
            param.errorMessage = false;
            temp[this.props.param.name] = param;
            this.props.changState(temp);
        },
        setFormValue: function (item) {

            var data = this.props.getState("data") || {}, param = this.props.param, vaMessage = "", temp = {};
            data[item.name] = item.value;
            if (typeof(item.name) == "string") {
                data[item.name] = item.value;
            } else if (item.name instanceof Array) {
                for (var i = 0; i < item.name.length; i++) {
                    data[item.name[i]] = item.value[item.name[i]];
                }
            }
            ;
            if (item.name == this.props.name) {
                if (item.value == "" && param.isStar) {
                    param.errorMessage = "不能为空!";
                } else if (param.vaMethod) {
                    vaMessage = param.vaMethod(item.value, this);
                    param.errorMessage = vaMessage;
                } else {
                    param.errorMessage = true;

                }
                temp[this.props.param.name] = param;

            }
            temp.data = data;

            //console.info("----------------------------------"+JSON.stringify(temp))
            this.props.changState(temp);


            /*this.props.changState({
             "data": data
             })*/
            // //console.log("表单数据:" + JSON.stringify(data));

        },
        changeSelfState: function (item) {
            this.props.changState(temp);
        },
        render: function () {
            var isShow = "from-area " + (this.props.param.isShow == false ? "hide" : "");            
            var cssLength = "from-in-area " + this.props.css[this.props.param.csslength];
            var defaultValue = this.props.param.defaultValue ? this.props.param.defaultValue : "";
            return (
                <div className={isShow}>
                    <label className="form-label">
                        {this.props.param.title}
                        {(() => {
                            if (this.props.param.isStar == true) {
                                return (
                                    <i className="i-red">*</i>
                                )
                            }
                        })()}

                        {this.props.param.isShowColon ? ":" : ""}
                    </label>
                    <div className={cssLength}>
                        {(() => {
                            switch (this.props.param.type.toLocaleUpperCase()) {
                                case "INPUT":
                                    return (
                                        <INPUT
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "INPUTMLEAVE":
                                    return (
                                        <INPUTMLEAVE
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "INPUT_DISPLAY":
                                    return (
                                        <INPUT_DISPLAY
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "INPUT_LABEL":
                                    return (
                                        <INPUT_LABEL
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            subTitle={this.props.param.subTitle}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "TEXTAREA":
                                    return (
                                        <TEXTAREA
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "SELECT":
                                    return (
                                        <SELECT
                                            vaIsDo={this.props.param.vaIsDo}
                                            defaultShowName={this.props.param.defaultShowName}
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                            isAuto={!!this.props.param.isAuto}
                                        />
                                    );
                                case "SELECT_BY_PARAM":
                                    return (
                                        <SELECT vaIsDo={this.props.param.vaIsDo}
                                            defaultShowName={this.props.param.defaultShowName}
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            changeSelfState={this.changeSelfState}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                            searchParam={this.props.param.searchParam} isAuto={this.props.param.isAuto}
                                            reFreshNum={this.props.param.reFreshNum}/>
                                    )
                                case "SELECT_STATIC":
                                    return (
                                        <SELECT_STATIC
                                            defaultShowName={this.props.param.defaultShowName}
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            changeSelfState={this.changeSelfState}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                            Data={this.props.param.Data}
                                            searchParam={this.props.param.searchParam}
                                            isAuto={this.props.param.isAuto}
                                            reFreshNum={this.props.param.reFreshNum}/>
                                    );
                                case "RADIO":
                                    return (
                                        <RADIO
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            changeSelfState={this.changeSelfState}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                            url={this.props.param.url}
                                            searchParam={this.props.param.searchParam}/>
                                    );
                                case "RADIO_STATIC":
                                    return (
                                        <RADIO_STATIC
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            changeSelfState={this.changeSelfState}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                            data={this.props.param.data}
                                            searchParam={this.props.param.searchParam}/>
                                    );
                                case "CHECKBOX":
                                    return (
                                        <CHECKBOX
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            changeSelfState={this.changeSelfState}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                            url={this.props.param.url}
                                            searchParam={this.props.param.searchParam}
                                        />
                                    );
                                case "LIST_SELECT":
                                    return (
                                        <LIST_SELECT
                                            defaultShowName={this.props.param.defaultShowName}
                                            placeholder={this.props.param.placeholder}
                                            url={this.props.param.url || ''}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            keyName={ this.props.param.keyName}
                                            defaultValue={defaultValue}
                                            valuekey={this.props.param.valuekey}
                                        />
                                    );
                                case "UPIMAGE":
                                    return (
                                        <UPIMGAE
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                case "CALENDAR":
                                    return (
                                        <CALENDAR
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            subTitle={this.props.param.subTitle}
                                            defaultValue={defaultValue}
                                        />
                                    );
                                default:
                                    return (
                                        <INPUT
                                            placeholder={this.props.param.placeholder}
                                            name={this.props.param.name}
                                            setFormValue={this.setFormValue}
                                            handleFocus={this.handleFocus}
                                            handleBlur={this.handleBlur}
                                            defaultValue={defaultValue}
                                        />
                                    )
                            }
                        })()}
                        <VALIDE errorMessage={this.props.param.errorMessage} name={this.props.name}/>
                    </div>
                </div>
            )
        }

    })
    module.exports =  {
        IN: IN,
    }
